package com.netease.pris.persist;

import com.db4o.ObjectSet;
import com.netease.pris.meta.Host;
/**
 * 
 * @author Administrator
 *
 */
public final class HostPersist extends BasePersist{
	
	private static HostPersist persist = new HostPersist();
	
	private HostPersist(){
	}
	
	public static HostPersist getHostPersist(){
		return persist;
	}
	
	public void addHost(Host host){
		getContainer().store(host);
	}
	
	public void updateHost(Host host){
		getContainer().store(host);
	}
	
	public Host queryHostByDesc(String desc) {
		Host query = new Host();
		query.setDescription(desc);
		ObjectSet<Host> hosts = getContainer().queryByExample(query);
		if (hosts != null && hosts.size() > 0) {
			return hosts.get(0);
		}
		return null;
	}
	
	public Host queryHostById(String id){
		Host h =  new Host();
		h.setHostId(id);
		ObjectSet<Host> hosts = getContainer().queryByExample(h);
		if(hosts != null && hosts.size()>0){
			return hosts.get(0);
		}
		return null;
	}
	
	public void deleteHost(Host host){
		Host h = queryHostById(host.getHostId());
		getContainer().delete(h);
	}
	
	public ObjectSet<Host> getAllHost(){
		return getContainer().query(Host.class);
	}
	
	public ObjectSet<Host> queryHost(Host host){
		return getContainer().queryByExample(host);
	}
}
